package org.example.interceptor;

import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;

import java.util.Map;

/**
 * @ClassName TimeInterceptor
 * @Author 小坏
 * @Date 2021/11/3、17:12
 * @Version 1.0
 */
public class TimeInterceptor implements ProducerInterceptor<String, String> {
    @Override
    public void configure(Map<String, ?> configs) {

    }

    @Override
    public ProducerRecord<String, String> onSend(ProducerRecord<String, String> record) {
        //1、取出数据
        String value = record.value();


        return new ProducerRecord<String, String>(record.topic(), record.partition(), record.key()
                , System.currentTimeMillis() + "," + value);
    }

    /**
     * 时间拦截器处理业务比较复杂的场景
     * @param metadata
     * @param exception
     */
    @Override
    public void onAcknowledgement(RecordMetadata metadata, Exception exception) {

    }

    @Override
    public void close() {

    }


}
